package com.missilike.api.controller;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.missilike.core.enums.SmsType;
import com.missilike.core.result.BizResultCode;
import com.missilike.core.result.CommonResult;
import com.missilike.core.service.IJPushService;
import com.missilike.core.utils.ResultUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: starmile
 * @Description:
 * @Create: 2019-01-10 23:13
 **/
@Slf4j
@RestController
@RequestMapping("/api/jpush")
public class JPushController {
    private IJPushService jPushService;

    public JPushController(IJPushService jPushService) {
        this.jPushService = jPushService;
    }

    @ApiOperation(value = "pushMassage", notes = "推送全平台消息")
    @RequestMapping(value = "/pushMassage", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public CommonResult pushMassage(@RequestParam String massage) {
        Boolean result = jPushService.pushAll(massage);
        return result ? ResultUtils.ok() : ResultUtils.error(BizResultCode.PUSH_ALL_MASSAGE_ERROR);
    }

    @ApiOperation(value = "pushAndroidMassage", notes = "推送安卓平台消息")
    @RequestMapping(value = "/pushAndroidMassage", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public CommonResult pushAndroidMassage(@RequestParam String tag, String title, String massage) {
        Boolean result = jPushService.pushAndroidByTag(tag, title, massage);
        return result ? ResultUtils.ok() : ResultUtils.error(BizResultCode.PUSH_ALL_MASSAGE_ERROR);
    }

    @ApiOperation(value = "pushIosMassage", notes = "推送ios平台消息")
    @RequestMapping(value = "/pushIosMassage", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public CommonResult pushIosMassage(@RequestParam String tag, String title, String massage) {
        Boolean result = jPushService.pushIosByTag(tag, title, massage);
        return result ? ResultUtils.ok() : ResultUtils.error(BizResultCode.PUSH_ALL_MASSAGE_ERROR);
    }
}
